import {UPDATE_AUTHORITY_INFO,DELETE_AUTHORITY_INFO,STATE_INIT} from "./types";
export default {
    [UPDATE_AUTHORITY_INFO](state, payload){
        // adminname: "",
        // role: null,
        // checkedkeys: [],
        // token: null,

        // 直接赋值 => 如果payload 只改变其中的一部分参数  => 有问题
        // state.adminname = payload.adminname
        // state.role = payload.role
        // state.checkedkeys = payload.checkedkeys
        // state.token = payload.token

        // for(var key in payload){
        //     var val = payload[key]
        //     state[key] = val;
        // }
        // Object.assign(state,payload);


        // 有值 -> 且在status中存在 -> 再改
        for(var key in payload){
            var val = payload[key]
            if(Object.keys(state).includes(key)&&val!=undefined){
                state[key] = val;
            }
        }
    },
    [DELETE_AUTHORITY_INFO](state){
        var data = JSON.parse(JSON.stringify(STATE_INIT));
        Object.assign(state,data);
    }
}